package Kalah;

import java.awt.BorderLayout;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.GridBagLayoutInfo;
import java.awt.GridLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;

import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.SwingConstants;
import javax.swing.border.Border;
import javax.swing.border.EmptyBorder;

public class KalahFrame extends JFrame implements ActionListener {
	private JMenu m_gameMenu;
	private JMenuItem m_newGameItem;
	private JMenuItem m_exitItem;
	private static KalahFrame m_ref;
	public void buildMenu() {
		JMenuBar mb = new JMenuBar();
		m_gameMenu = new JMenu("Game");
		m_gameMenu.setMnemonic(KeyEvent.VK_G);
		m_newGameItem = new JMenuItem("New Game");
		m_newGameItem.setMnemonic(KeyEvent.VK_N);
		m_newGameItem.addActionListener(this);
		m_exitItem = new JMenuItem("Exit");
		m_exitItem.setMnemonic(KeyEvent.VK_X);
		m_exitItem.addActionListener(this);
		m_gameMenu.add(m_newGameItem);
		m_gameMenu.add(m_exitItem);
		mb.add(m_gameMenu);
		add(mb, BorderLayout.NORTH);
	}

	private KalahFrame() {
		super("Kalah Game!");
		setLayout(new BorderLayout());
		buildMenu();
		// if game is started 
		add(KalahGamePanel.getInstance());
		setSize(650, 375);
		setLocationRelativeTo(null);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	}
	public static KalahFrame getInstance(){
		if(m_ref == null)
			m_ref = new KalahFrame();
		return m_ref;
	}
	@Override
	public void actionPerformed(ActionEvent arg0) {
		if (arg0.getSource().equals(m_exitItem)) {
			System.exit(0);
		}
		else if (arg0.getSource().equals(m_newGameItem)) {
			NewOptionsMenu.getInstance().setVisible(true);
		}
	}

	

}
